package com.casic.ops.entity.vo.pipeline;

import com.casic.ops.consts.app.PipelineDetailStatus;
import com.casic.ops.consts.app.StageType;
import com.casic.ops.entity.domain.ApplicationPipelineTaskDetailDO;
import com.casic.ops.entity.domain.pipeline.PipelineNodeLoggerDO;
import com.casic.ops.entity.vo.ApplicationPipelineTaskStatisticsDetailVO;
import com.casic.ops.utils.Utils;
import lombok.Data;

import java.util.Date;
@Data
public class PipelineStaticsticsNodeloggerVO {

    /**
     * id
     *
     */
    private String nodeUuid;

    /**
     * 操作id
     */
    private Long detailId;

//    /**
//     * 引用id
//     */
//    private Long relId;

    /**
     * 阶段类型 10构建 20发布
     *
     * @see StageType
     */
    private Integer stageType;

    /**
     * 状态 10未开始 20进行中 30已完成 40执行失败 50已跳过 60已终止
     *
     * @see PipelineDetailStatus
     */
    private Integer status;

    /**
     * 操作时长 (任何状态)
     */
    private Long used;

    /**
     * 操作时长 (任何状态)
     */
    private String usedInterval;

    public static PipelineStaticsticsNodeloggerVO PipelineNodeLoggerDo2PipelineStaticsticsNodeLoggerDo(PipelineNodeLoggerDO p) {
        PipelineStaticsticsNodeloggerVO  vo = new PipelineStaticsticsNodeloggerVO();
        vo.setNodeUuid(p.getNodeUuid());
        vo.setStageType(10);
        if(p.getFinalStatus().equals("成功")){
            vo.setStatus(30);
        }else if(p.getFinalStatus().equals("待执行")){
            vo.setStatus(60);
        }else {
            vo.setStatus(40);
        }
        Date startTime = p.getExecuteStartTime();
        Date endTime = p.getExecuteEndTime();
        if (startTime != null && endTime != null) {
            long used = endTime.getTime() - startTime.getTime();
            vo.setUsed(used);
            vo.setUsedInterval(Utils.interval(used));
        }
        return vo;
    }

    @Override
    public String toString() {
        return "PipelineStaticsticsNodeloggerVO{" +
                "id=" + nodeUuid +
                ", detailId=" + detailId +
                ", stageType=" + stageType +
                ", status='" + status + '\'' +
                ", used=" + used +
                ", usedInterval='" + usedInterval + '\'' +
                '}';
    }
}
